﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;
using System.Collections;

namespace OptusMobile.Web.Handset
{
    public partial class Handset : System.Web.UI.MasterPage
    {
        private XmlDocument xmlDoc;

        public Handset()
        {
            xmlDoc = new XmlDocument();
           
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            xmlDoc.Load(Server.MapPath("../Handset/ShoppingCarXML.xml"));
            if (Session["flag"] == null)
            {
                //Response.Redirect("../Default.aspx");
                this.Label1.Visible = false;
                this.lblogin.Visible = false;
                this.LinkButton1.Text = "Login";
            }
            else
            {
                string name = Session["flag"].ToString();
                string type = "user";
                if (name.Equals(type))
                {
                    string loginname = Session["ID"].ToString();
                    this.lblogin.Text = loginname;
                }
                else
                {
                    //Response.Redirect("../Default.aspx");
                }
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session.Abandon();

            XmlNodeList xnl = xmlDoc.SelectSingleNode("item").ChildNodes;
            int count = xnl.Count;
            for (int i = 0; i < count; i++)
            {
                foreach (XmlNode xn in xnl)
                {
                    XmlElement xe = (XmlElement)xn;

                    if (xe.GetAttribute("ID") == Session.SessionID)
                    {
                        xe.ParentNode.RemoveChild(xe);
                    }
                }
            }
            xmlDoc.Save(Server.MapPath("../Handset/ShoppingCarXML.xml"));
            Response.Redirect("../Default.aspx");
            
        }
    }
}
